﻿<UserControl x:Class="StockholmsStad.Windows.UI.Modules.Maintenance.Controls.GeneratedDaysControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:localconverter="clr-namespace:StockholmsStad.Windows.UI.Modules.Maintenance.Converters"
    xmlns:converters="clr-namespace:StockholmsStad.Windows.UI.Infrastructure.Converters;assembly=StockholmsStad.Windows.UI.Infrastructure">
    <UserControl.Resources>
        <converters:DateTimeToHourMinuteString x:Key="HourConverter" />
        <converters:DateTimeToDateString x:Key="DateConverter" />
        <localconverter:TimeBlockTypeToString x:Key="TimeBlockTimeConverter" />

        <!--Define the template for the first column to contain a CheckBox control-->
        <DataTemplate x:Key="SelectionCell">
            <StackPanel Orientation="Horizontal">
                <CheckBox IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}"/>
            </StackPanel>
        </DataTemplate>
   
    </UserControl.Resources>

    <Grid Margin="15,0,0,0" VerticalAlignment="Stretch">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        
        <StackPanel Orientation="Horizontal" Margin="0,0,0,0" Grid.Row="0">
            <Label Content="Valt datum:" VerticalAlignment="Center" />
            <TextBlock x:Name="lbSelectedDate" VerticalAlignment="Center" Text="{Binding Path=Date, Converter={StaticResource DateConverter}}" />
        </StackPanel>
        
        <ListView x:Name="lvDates" SelectionMode="Multiple" VerticalAlignment="Top" Grid.Row="1" MaxHeight="400"
                      ItemsSource="{Binding Path=MinisterTimeBlocks}" ItemContainerStyle="{DynamicResource ListItemContainerStyle}" 
                      ScrollViewer.HorizontalScrollBarVisibility="Disabled" CheckBox.Unchecked="OnUncheckItem">
            <ListView.View>
                <GridView>
                    <GridViewColumn CellTemplate="{StaticResource SelectionCell}" Width="50">
                        <GridViewColumn.Header>
                            <CheckBox x:Name="cbSelectAll" Style="{DynamicResource CheckBoxHeaderStyle}" Content="Välj" 
                                          Click="OnSelectAllChanged" Padding="5,0,0,0" HorizontalAlignment="Left" Margin="0,0,0,0" />
                        </GridViewColumn.Header>
                    </GridViewColumn>

                    <GridViewColumn Header="Tid" DisplayMemberBinding="{Binding StartDateTime, Converter={StaticResource HourConverter}}" Width="45"/>
                    <GridViewColumn Header="Typ" DisplayMemberBinding="{Binding TimeBlockStatus, Converter={StaticResource TimeBlockTimeConverter}}" Width="40" />
                    <GridViewColumn Header="Förrättare" DisplayMemberBinding="{Binding Minister.FullName}" Width="120"/>
                    <GridViewColumn Header="Vik. Förrättare" DisplayMemberBinding="{Binding TempMinister.FullName}" Width="120"/>
                </GridView>
            </ListView.View>
        </ListView>

        <StackPanel Orientation="Horizontal" Margin="0,20,0,0" Grid.Row="2">
            <CheckBox x:Name="cbInactive" Grid.Column="0" Content="Sätt paus" Padding="6,0,0,0" VerticalAlignment="Center" IsChecked="False" Checked="cbInactive_Checked" />
            <CheckBox x:Name="cbActive" Grid.Column="0" Content="Sätt aktiv" Padding="6,0,0,0" VerticalAlignment="Center" IsChecked="False" Margin="25,0,0,0" Checked="cbActive_Checked" />
        </StackPanel>

        <StackPanel Orientation="Horizontal" Margin="0,15,0,0" Grid.Row="3">
            <ComboBox x:Name="cbMinisters" Width="240" Height="24" ItemsSource="{Binding Ministers}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Path=MinisterId}" Visibility="Hidden" />
                            <TextBlock Text="{Binding Path=FullName}" />
                        </StackPanel>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <CheckBox x:Name="cbTempMinister" Content="Vik. förrättare" IsChecked="False" Margin="15,0,10,0" Padding="6,0,0,0" VerticalAlignment="Center" />
        </StackPanel>
        
        <Button Content="Tilldela" Grid.Row="4" Height="24" Width="70" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,10,0,0" Click="btnAssign_Click" />

        <StackPanel Orientation="Horizontal" Grid.Row="5" HorizontalAlignment="Right" Margin="0,15,0,0">
            <Button x:Name="SaveButton" Content="Spara" Margin="0,10,0,0" Command="{Binding SaveCommand}" />
            <Button x:Name="CancelButton" Content="Ångra" Margin="5,10,0,0" Command="{Binding CancelCommand}" />
        </StackPanel>

    </Grid>

</UserControl>